<template>
  <div class="app-container">
    <basic-container v-show="showSearch">
      <common-search @handleQuery="handleQuery" @resetQuery="resetQuery">
        <el-form :model="queryParams" ref="queryForm" :inline="true" size="mini" label-width="100px">
          <el-form-item label="企业代码" prop="entCode">
            <el-select v-model.trim="queryParams.entCode" placeholder="请选择企业代码" clearable>
              <el-option label="请选择字典生成" value="" />
            </el-select>
          </el-form-item>
          <el-form-item label="身份证号码" prop="idNo">
            <el-input v-model.trim="queryParams.idNo" placeholder="请输入身份证号码" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="姓名" prop="name">
            <el-input v-model.trim="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="电话" prop="telephone">
            <el-input v-model.trim="queryParams.telephone" placeholder="请输入电话" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="邮箱" prop="email">
            <el-input v-model.trim="queryParams.email" placeholder="请输入邮箱" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="账号" prop="account">
            <el-input v-model.trim="queryParams.account" placeholder="请输入账号" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="daterangeCreateTime" class="reset-clear" type="datetimerange" :clearable="false"
              unlink-panels start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']" />
          </el-form-item>

        </el-form>
      </common-search>
    </basic-container>

    <basic-container>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddEdit('add')"
            v-hasPermi="['system:enterpriseOper:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['system:enterpriseOper:remove']">删除</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['system:enterpriseOper:export']"
          >导出</el-button>
        </el-col>
        -->

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <!-- 列表 -->
      <basic-table ref="tableList" :columns="columns" :tableData="tableData" :total="pageParams.total"
        @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :loading="loading"
        :needCheckbox="true" @selectionChange="handleSelectionChange">


        <template #operate="scope">
          <div class="option-menu">
            <el-button type="text" size="mini" class="table-edit" @click="handleAddEdit('edit', scope.row)"
              v-hasPermi="['system:enterpriseOper:edit']">
              编辑
            </el-button>
            <el-button type="text" size="mini" class="table-edit" @click="handleDelete(scope.row)"
              v-hasPermi="['system:enterpriseOper:remove']">
              删除
            </el-button>
            <el-button type="text" size="mini" class="table-edit" @click="handleDetail(scope.row)">
              详情
            </el-button>
          </div>
        </template>
      </basic-table>
    </basic-container>

    <!-- 新增、编辑 -->
    <add-edit ref="addEdit" :dialogType="dialogType" :rowData="rowData" :dict="dictProp" @handleQuery="handleQuery" />

    <!-- 详情 -->
    <detail-dialog ref="detail" :detailId="detailId" :dict="dictProp"></detail-dialog>

  </div>
</template>

<script>
  import {
    listEnterpriseOper,
    delEnterpriseOper,
    exportEnterpriseOper
  } from "@/api/system/enterpriseOper";
  import addEdit from "./components/addEdit";
  import detailDialog from "./components/detailDialog";
  export default {
    name: "EnterpriseOper",
    components: {
      addEdit,
      detailDialog
    },
    data() {
      return {
        // 显示搜索条件
        showSearch: true,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          entCode: null,
          idNo: null,
          name: null,
          telephone: null,
          email: null,
          account: null,
          createTime: null,
        },
        // 遮罩层
        loading: true,
        // 列表数据
        tableData: [],
        columns: [{
            prop: "entCode",
            label: "企业代码",
            align: "center"
          },

          {
            prop: "idNo",
            label: "身份证号码",
            align: "center"
          },

          {
            prop: "name",
            label: "姓名",
            align: "center"
          },

          {
            prop: "telephone",
            label: "电话",
            align: "center"
          },

          {
            prop: "email",
            label: "邮箱",
            align: "center"
          },

          {
            prop: "account",
            label: "账号",
            align: "center"
          },

          {
            prop: "createTime",
            label: "创建时间",
            align: "center"
          },

          {
            prop: "createBy",
            label: "创建人",
            align: "center"
          },

          {
            prop: "updateTime",
            label: "更新时间",
            align: "center"
          },

          {
            prop: "updateBy",
            label: "更新人",
            align: "center"
          },

          {
            prop: "operate",
            label: "操作",
            slot: true,
            width: 140,
            fixed: "right",
          },
        ],
        pageParams: {
          total: 0,
        },
        rowData: {},
        detailId: "",
        dialogType: "",
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        //详情显示的时候，表单编辑禁用
        isViewDisabled: false,

        // 企业操作员表格数据
        enterpriseOperList: [],
        // 更新人时间范围
        daterangeCreateTime: [],
      };
    },
    computed: {
      dictProp() { //字典list，为避免子组件重复调接口获取，用computed计算传值
        return {
          type: ''
        }
      }
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询企业操作员列表 */
      getList() {
        this.loading = true;
        // this.queryParams.params = {};
        this.addDateRange(this.queryParams, this.daterangeCreateTime)
        listEnterpriseOper(this.queryParams).then(response => {
          this.tableData = response.rows;
          this.pageParams.total = response.total;
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.$refs.tableList.pageParams.currentPage = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeCreateTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 分页
      handleSizeChange(val) {
        this.queryParams.pageSize = val.pageSize;
        this.getList();
      },
      handleCurrentChange(val) {
        this.queryParams.pageNum = val.currentPage;
        this.getList();
      },
      // 新增/编辑
      handleAddEdit(type, row) {
        this.dialogType = type;
        if (row) {
          this.rowData = JSON.parse(JSON.stringify(row));
        }
        this.$refs.addEdit.open();
      },
      // 详情
      handleDetail(row) {
        this.detailId = row.id;
        this.$nextTick(() => {
          this.$refs.detail.open(row);
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除企业操作员编号为"' + ids + '"的数据项？').then(function() {
          return delEnterpriseOper(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      }
    }
  };
</script>



<style type="text/css">
  .el-form-item .el-select {
    width: 100%;
  }
</style>
